
 <!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-03-07 14:03:46
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2023-06-30 15:11:06
 * @FilePath: \newMould_BHZ\src\views\WaterManage\analyse\percentage.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->

  
<template>
  <!--   水稳--- 智能监控----联网状态 -->
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left"></div>
        <!-- 顶部按钮 -->
        <div class="print" style="justify-content: flex-end">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="small"
            @click="yj_editForm()"
          >
            拌合机绑定</el-button
          >
        </div>
      </div>
      <!-- 列表 -->
      <div v-if="!pageFlag" class="networkStatus">
        <div
          class="networkStatusBigBox"
          v-for="(item, index) in tableData"
          :key="index"
        >
          <div class="networkImg">
            <img :src="item.STATUS == 0 ? online2 : online1" alt="" />
          </div>
          <div class="networkInfo">
            <div class="bhClass bhjname">
              {{ item.F_MachineName }}/{{ item.F_StationName }}
            </div>
            <div class="bhClass bhjid">拌合机ID：{{ item.F_MachineId }}</div>
            <div class="bhClass bhjid">拌合站ID：{{ item.F_StationId }}</div>
            <div class="bhClass bhjid">
              上传时间：{{ item.F_DischargeDates }}
            </div>
          </div>
          <div class="btn">
            <!-- 0:停用 1：启用 -->
            <el-switch
              :value="item.F_ActiveStatus | status"
              :active-text="
                item.F_ActiveStatus == 0
                  ? '停用'
                  : item.F_ActiveStatus == 1
                  ? '启用'
                  : '未启用'
              "
            >
            </el-switch>
          </div>
        </div>
      </div>
      <div v-if="pageFlag" class="pageFlag">
        <img src="@/assets/img/undata.png" alt="" />
        <div class="pageFlagText">暂时没有数据哦！</div>
      </div>
    </div>

    <!-- 绑定拌合机弹框 -->
    <div class="Control-1 mechanism_dialogS">
      <el-dialog
        title="新增"
        :modal-append-to-body="false"
        v-dialogDrag
        :visible.sync="dialogVisible"
        v-loading="loadingDialog"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
      >
        <div class="dialogBody common" :style="{ height: '550px' }">
          <noData v-if="machineList.length == 0"></noData>
          <div v-else class="addMemberCheckLeft addMachine">
            <el-checkbox-group
              v-model="checkMachine"
              @change="selectMachine($event)"
            >
              <el-checkbox-button
                v-for="item in machineList"
                :label="item.F_MachineId"
                :key="item.F_MachineId"
                :value="item.F_MachineName"
              >
                <div class="addMemberCheck">
                  <div class="MemberIcon">机</div>
                  <div class="MemberDetailInfos">
                    <div class="name">
                      {{ item.F_MachineName }}/{{ item.F_StationName }}
                    </div>
                    <div class="hostName">{{ item.F_MachineId }}</div>
                  </div>
                </div>
              </el-checkbox-button>
            </el-checkbox-group>
            <!-- </div> -->
          </div>
          <div v-if="machineList.length != 0" class="newlyAdded_btn">
            <el-button type="primary" @click="yj_saveObjectForm()"
              >保存</el-button
            >
            <el-button type="warning" @click="dialogVisible = false"
              >关闭</el-button
            >
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import tree from "@/components/public/waterManage_tree"; //左侧机构树
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import noData from "@/components/public/noData.vue";

import {
  getUserCompanyTreeList, //左侧机构树接口
  getWaterMachineStatus, // 拌合机在线状态
  getWaterMachineList, // 新增按钮拌合机状态
  addMachineActive, // 保存按钮拌合机状态
} from "@/api/request.js";
export default {
  name: "networking",
  components: {
    tree, //左侧组织机构数
    elBreadcrumb, //面包屑
    noData,
  },
  data() {
    return {
      name: "networking", //按钮配置页面代号
      userInfo: {}, //登录用户

      // 列表页
      pageFlag: true, //无数据页面显示隐藏
      online2: require("@/assets/img/waterMange/LwN.png"),
      online1: require("@/assets/img/waterMange/LwY.png"),
      listLoading: false, //列表数据加载loading
      // getList: {
      //   companyId: "", // 施工标段id
      //   startDates: "", // 开始时间
      //   endDates: "", // 截至时间
      //   machineId: "", // 拌和机编号
      //   enCode: "",
      // }, // 列表给后端传参

      getList: {
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 拌合站id
        machineId: "", // 拌合机id
        buildPart: "", // 施工部位
        page: "", // 当前页数
        pageSize: "", // 每页显示条数
      },
      tableData: [], //列表页数据
      // 列表页

      // 拌和机绑定弹框
      machineList: [], //拌合机列表
      loadingDialog: false, //拌合机绑定loading
      dialogVisible: false, //拌合机绑定dialog
      checkMachine: [],

      // 拌和机绑定弹框

      // 左侧机构树
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      // checked: true, //查看下级按钮
      showName: "未选择公司",
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      // 左侧机构树
    };
  },
  filters: {
    status(data) {
      var status;
      if (data == 1) {
        status = true;
      } else if (data == 0) {
        status = false;
      }
      return status;
    },
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));

    if (JSON.parse(sessionStorage.getItem("waterManage_getLists"))) {
      this.getList = JSON.parse(sessionStorage.getItem("waterManage_getLists"));
    }

    if (JSON.parse(sessionStorage.getItem("waterManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("waterManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
  },

  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
      }
    },

    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "2", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("waterManage_treeCheck")
              ).fShortname;

              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }

            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.fCompanyid = data.fCompanyid;
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      window.sessionStorage.setItem(
        "waterManage_getLists",
        JSON.stringify(data)
      );
      getWaterMachineStatus({
        fCompanyid: this.getList.fCompanyid, // 施工标段id
      })
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            if (res.data.length > 0) {
              this.tableData = res.data;
              this.pageFlag = false;
            } else {
              this.pageFlag = true;
            }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
        });
    },
    // 新增编辑
    yj_editForm() {
      // 打开绑定拌和机弹框
      this.loadingDialog = true;
      this.dialogVisible = true;

      getWaterMachineList({ fCompanyid: this.getList.fCompanyid }).then(
        (res) => {
          if (res.errcode == 0) {
            this.loadingDialog = false;
            this.machineList = res.data;
          } else {
            this.$message.error("获取拌和机列表接口报错");
          }
        }
      );
    },
    // 绑定拌和机保存接口
    yj_saveObjectForm() {
      //绑定拌合机
      if (this.selectMachineList.length > 0) {
        addMachineActive({ machineIds: this.selectMachineList }).then((res) => {
          if (res.errcode == 0) {
            this.dialogVisible = false;
            this.yj_searchForm(this.getList);
            this.$message.success("绑定成功");
          } else {
            this.$message.error("绑定拌和机保存接口报错");
          }
        });
      } else {
        this.$message.warning("请选择需要绑定的拌和机");
      }
    },
    // 点击拌和机得到拌和机machineId数组
    selectMachine(e) {
      this.selectMachineList = e;
    },
  },
};
</script>

<style scoped lang="less">
.networkStatus {
  // background: pink;
  flex: 1;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  box-sizing: border-box;
  min-width: 740px;

  .networkStatusBigBox {
    background-color: #fafafa;
    border: 1px solid #ccc;
    height: 32.6%;
    height: 35%;

    // height: 100rpx;
    // 每个元素都要设置右边距margin-right（每个元素的左右间隙）
    // 同时设置下边距margin-bottom（每个元素的上下间隙）
    margin: 0 10px 10px 0;
    width: calc((100% - 40px) / 5);
    // 这里一行显示4个，所以是/4，一行显示几个就除以几
    // 这里的60rpx = (分布个数4-1)*间隙20rpx, 可以根据实际的分布个数和间隙区调整
    min-width: calc((100% - 40px) / 5);
    max-width: calc((100% - 40px) / 5);
    border-radius: 10px;
    box-sizing: border-box;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;

    .networkImg {
      // height: 150px;
      height: 45%;
      // background: pink;
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        // width: 100%;
        min-width: 30%;
        min-height: 80%;
        max-height: 90%;
        // width: 30%;
        // min-width: 30%;
        // min-height: 60%;
        // max-height: 90%;
      }
    }

    .networkInfo {
      height: 40%;
      border-bottom: 1px solid #eee;
      // background: red;
      font-size: 12px;
      padding: 0;
      display: flex;
      flex-direction: column;

      .bhClass {
        display: flex;
        // justify-content: center;
        align-items: center;
        height: 25%;

        overflow: hidden; //（文字长度超出限定宽度，则隐藏超出的内容）
        white-space: nowrap; //（设置文字在一行显示，不能换行）
        text-overflow: ellipsis; //（规定当文本溢出时，显示省略符号来代表被修剪的文本）
      }

      .bhjname {
        color: #171a1d;
        font-weight: 700;
        font-size: 0.16rem;
      }

      .bhjid {
        color: #858687;

        font-size: 0.14rem;
        // line-height: 1;
        // height: 0.23rem;
        height: 25%;
      }
    }

    .btn {
      height: 15%;
      font-size: 0.14rem;
    }

    // 每行最右侧的那个不设置右外边距
    &:nth-child(5n + 5) {
      margin-right: 0;
    }

    &:hover {
      /* 盒子向上移动 */
      transform: translateY(-1px);
      /* 背景 */
      box-shadow: 0 20px 80px rgba(48, 49, 51, 0.15);
    }
  }
}

.addMemberCheckLeft {
  width: 98%;
  padding: 0 0 0 20px;
  // border-top: 1px solid rgba(221, 221, 221, 1);
  // border-bottom: 1px solid rgba(221, 221, 221, 1);
  // border-right: 1px solid rgba(221, 221, 221, 1);

  .addMemberCheck {
    width: 233px;
    height: 64px;
    border-radius: 2px;
    display: flex;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
  }
}

.addMemberCheck .MemberIcon {
  /* height: 100%; */
  /* height: 54px; */
  height: 62px;
  width: 64px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 28px;
  color: #fff;
  // margin-right: 8px;
  background: rgba(224, 224, 224, 1);
}

// .MemberIcon img {
//     width: 37.81px;
//     height: 39.38px;
//     border-radius: 50%;
// }

.MemberDetailInfos {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;

  .name {
    color: rgba(51, 51, 51, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
  }

  .hostName {
    color: rgba(128, 125, 125, 1);
    font-size: 12px;
    height: 20px;
    line-height: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.MemberIcon .name {
  color: rgba(51, 51, 51, 1);
  font-size: 12px;
  height: 20px;

  line-height: 20px;
}

.MemberIcon .hostName {
  color: rgba(128, 125, 125, 1);
  font-size: 12px;
  height: 20px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pageFlag {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  justify-content: center;
  align-items: center;
  color: #171a1d;
  font-size: 16px;
  // background: pink;

  img {
    width: 258px;
    height: 208px;
  }

  .pageFlagText {
    margin-top: 33px;
  }

  .pageFlagTexts {
    font-size: 14px;
    color: #a2a4a7;
  }
}

.addMachine /deep/.el-checkbox-button {
  width: 235px;
  height: 64px;
}

#smallDialog /deep/.el-dialog {
  width: 700px !important;
}
</style>
